import { Alert, Expander, ExpanderItem, ScrollView } from '@aws-amplify/ui-react'; import ReactPropsTable from '@/components/propsTable/ReactPropsTable'; import { Example, ExampleCode } from '@/components/Example'; import { DELETE_USER, OVERRIDES, WARNING, DELETE_BUTTON } from './props'; import { ERROR_MESSAGE } from '../props'; ### Props ### Basic Usage `DeleteUser` has `onSuccess` handler that will be called after successful user account deletion. You may use this callback to run any custom handling, such as navigating route or rendering confirmation messages. ```jsx import React from 'react'; import { AccountSettings } from '@aws-amplify/ui-react'; function App() { const handleSuccess = () => { alert('user has been successfully deleted') } return ( ); } ``` ### Override default delete handler You can override the default deleteUser handler with `handleDelete` prop to add any custom cleanup handlers before or after account deletion. ```jsx import React from 'react'; import { Auth } from 'aws-amplify'; import { DeleteUser } from '@aws-amplify/ui-react'; function App() { const handleSuccess = () => { alert('password is successfully changed!') } const handleDelete = async () => { console.log("Doing some clean up..."); console.log("Done!"); await Auth.deleteUser(); }; return ( ); } ``` ### Component Overrides You can override parts of the `DeleteUser` component by passing in a `components` prop. It supports the following slots: #### Reusing default components Default components are accessible through `AccountSettings.DeleteUser.COMPONENT_NAME` (e.g. `AccountSettings.DeleteUser.DeleteButton`) for your convenience. This is useful if you're interested in modifying just a small part of UI instead of overriding the whole component. ```jsx function App() { const components = { DeleteButton: (props) => ( Custom Submit Button ), } return ( ); } ``` Note that spreading props is necessary so that event listeners like `onClick` or html attributes like `type` are passed correctly. If you're providing your own custom components, make sure required props are passed onto your elements. #### Props and Examples Here are the required props and examples for overriding each slot. Props: You can reuse the `AccountSettings.DeleteUser.DeleteButton`: ```jsx import { AccountSettings } from '@aws-amplify/ui-react'; function App() { const components = { DeleteButton: (props) => ( My Custom Button ) } return ( ); } ``` or use [button primitive](/components/button) directly: ```jsx import { AccountSettings, Button } from '@aws-amplify/ui-react'; function App() { const components = { DeleteButton: (props) => } return ( ); } ``` The following example replaces `DeleteButton` with native html button: ```jsx function App() { const components = { DeleteButton: ({ onClick, isDisabled }) => ( ) }; return ( ); } ``` Props: The following example overrides the error message component with [`Heading`](/components/heading) and [`Text`](/components/text) primitives. ```jsx import { Heading, Text } from '@aws-amplify/ui-react'; function App() { const components = { ErrorMessage: ({ children }) => ( <> Custom Error Message {children} ) }; return ( ); } ``` Props: The following example overrides the warning component to require users to type "delete" before they can delete their account. ```jsx{10-37,48} file=../../../../../../../examples/next/pages/ui/components/account-settings/delete-user-with-overrides/index.page.tsx#L1-L72 ``` ### Theming `DeleteUser` component is built upon our robust [Amplify UI theming system](../../theming). To get started, add a theme object and set the appropriate [design tokens](../../theming#design-tokens). You can then pass that `theme` to the `ThemeProvider` so the changes can take affect. ```jsx import { AccountSettings, Card, ThemeProvider } from '@aws-amplify/ui-react'; const theme = { name: 'custom-theme', tokens: { colors: { border: { primary: { value: '{colors.neutral.40}' }, secondary: { value: '{colors.neutral.20}' }, tertiary: { value: '{colors.neutral.10}' }, }, }, radii: { small: { value: '2px' }, medium: { value: '3px' }, large: { value: '4px' }, xl: { value: '6px' }, }, }, }; function App() { return ( ); } ```